package com.easylinkin.linkappapi.videomonitor.controller;

import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.device.entity.Device;
import com.easylinkin.linkappapi.videomonitor.service.DeviceVideoMonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @program: linkapp-group
 * @description: 视频监控
 * @author: chenkaixuan
 * @create: 2021-08-14 10:20
 */

@RestController
@RequestMapping("/deviceVideoMonitor")
public class DeviceVideoMonitorController {
    @Autowired
    DeviceVideoMonitorService service;

    @PostMapping("page")
    public RestMessage page(@RequestBody RequestModel<Device> requestModel){
        Assert.notNull(requestModel, "requestModel 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        return RestBuilders.successBuilder().data(service.page(requestModel.getPage(),requestModel.getCustomQueryParams())).build();
    }

    @PostMapping("pageNotBind")
    public RestMessage pageNotBind(@RequestBody RequestModel<Device> requestModel){
        Assert.notNull(requestModel, "requestModel 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        return RestBuilders.successBuilder().data(service.pageNotBind(requestModel.getPage(),requestModel.getCustomQueryParams())).build();
    }

    @PostMapping("saveBatchbind")
    public RestMessage saveBatchbind(@RequestBody Device device){
        service.saveBatchbind(device);
        return RestBuilders.successBuilder().build();
    }

    @PostMapping("getAll")
    public RestMessage getAll(@RequestBody Device device){
        return RestBuilders.successBuilder(service.getDeviceVideoMonitorAll(device)).build();
    }

    @PostMapping("delete")
    public RestMessage delete(@RequestBody Device device){
        service.delete(device);
        return RestBuilders.successBuilder().build();
    }

    @PostMapping("playback")
    public RestMessage playback(@RequestBody RequestModel<Device> requestModel){
        Assert.notNull(requestModel, "requestModel 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        return RestBuilders.successBuilder(service.playback(requestModel.getPage(),requestModel.getCustomQueryParams())).build();
    }
}
